let arr = [
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
  [{}, {}, {}, {}, {}, {}, {}, {}, {}],
]

//读取分数
const fenshu = document.querySelector('.fenshu')
const defen = document.querySelector('.defen')
let Fenshu = 0
let date = localStorage.getItem('fenshu1')
Fenshu = date || 0
fenshu.innerHTML = `最高分${Fenshu}`
let Defen = 0

//创建构造函数
function Obj(x, y) {
  this.x = x
  this.y = y
}
Obj.prototype = {
  constructor: Obj,
  //第一种类型
  Achange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
    } else {
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      arr[this.y + 2][this.x - 1].num = 1
      areg = 4
    }
  },
  //第一种类型清空
  Aclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y + 1][this.x + 1].num = 0
  },
  //第一种类型变灰
  AchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    get()
  },
  //第一种类型变形状
  Achange2: function () {
    if (arr[this.y][this.x + 1].num != 2 &&
      arr[this.y - 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2) {
      arr[this.y][this.x + 1].num = 1
      arr[this.y - 1][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      areg = 1
    }

  },
  Aclear2: function () {
    arr[this.y][this.x + 1].num = 0
    arr[this.y - 1][this.x + 1].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
  },
  AchangeColor2: function () {
    arr[this.y][this.x + 1].num = 2
    arr[this.y - 1][this.x + 1].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    get()
  },
  Achange3: function () {
    if (arr[this.y + 1][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y][this.x + 1].num = 1
      arr[this.y - 1][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      areg = 2
    }
  },
  //第一种类型清空
  Aclear3: function () {
    arr[this.y + 1][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  //第一种类型变灰
  AchangeColor3: function () {
    arr[this.y + 1][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  Achange4: function () {
    if (arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2 &&
      arr[this.y + 2][this.x - 1].num != 2) {
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      arr[this.y + 2][this.x - 1].num = 1
    } else {
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 3
    }
  },
  Aclear4: function () {
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x - 1].num = 0
    arr[this.y + 2][this.x - 1].num = 0
  },
  AchangeColor4: function () {
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    arr[this.y + 2][this.x - 1].num = 2
    get()
  },
  //第一种类型
  Fchange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
      areg = 54
    }
  },
  //第一种类型清空
  Fclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  //第一种类型变灰
  FchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  //第一种类型变形状
  Fchange2: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y - 1][this.x].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y - 1][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 51
    }

  },
  Fclear2: function () {
    arr[this.y][this.x].num = 0
    arr[this.y - 1][this.x].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
  },
  FchangeColor2: function () {
    arr[this.y][this.x].num = 2
    arr[this.y - 1][this.x].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    get()
  },
  Fchange3: function () {
    if (arr[this.y + 1][this.x].num != 2 &&
      arr[this.y][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y - 1][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      areg = 52
    }
  },
  //第一种类型清空
  Fclear3: function () {
    arr[this.y + 1][this.x].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  //第一种类型变灰
  FchangeColor3: function () {
    arr[this.y + 1][this.x].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  Fchange4: function () {
    if (arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 2][this.x].num != 2) {
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
    } else {
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 53
    }
  },
  Fclear4: function () {
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 2][this.x].num = 0
  },
  FchangeColor4: function () {
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 2][this.x].num = 2
    get()
  },
  //第二种类型
  Bchange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 2][this.x].num != 2 &&
      arr[this.y + 3][this.x].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
      arr[this.y + 3][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y][this.x + 2].num = 1
      areg = 12
    }
  },
  //第二种类型清空
  Bclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 2][this.x].num = 0
    arr[this.y + 3][this.x].num = 0
  },
  //第二种类型变灰
  BchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 2][this.x].num = 2
    arr[this.y + 3][this.x].num = 2
    get()
  },
  //第二种类型变形状
  Bchange2: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x + 1].num != 2 &&
      arr[this.y][this.x + 2].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y][this.x + 2].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
      arr[this.y + 3][this.x].num = 1
      areg = 11
    }
  },
  //清空
  Bclear2: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y][this.x + 2].num = 0
  },
  //变灰
  BchangeColor2: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y][this.x + 2].num = 2
    get()
  },
  //第三种类型
  Cchange1: function () {
    arr[this.y][this.x].num = 1
    arr[this.y][this.x + 1].num = 1
    arr[this.y + 1][this.x].num = 1
    arr[this.y + 1][this.x + 1].num = 1
  },
  //清空
  Cclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 1][this.x + 1].num = 0
  },
  //变灰
  CchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    get()
  },
  //第四种类型
  Dchange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
      areg = 34
    }
  },
  //清空
  Dclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  //变色
  DchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  Dchange2: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 2][this.x].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 31
    }
  },
  //清空
  Dclear2: function () {
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 2][this.x].num = 0
  },
  //变色
  DchangeColor2: function () {
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 2][this.x].num = 2
    get()
  },
  Dchange3: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x + 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
      areg = 32
    }
  },
  //清空
  Dclear3: function () {
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x + 1].num = 0
  },
  //变色
  DchangeColor3: function () {
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x + 1].num = 2
    get()
  },
  Dchange4: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 2][this.x].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 2][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x + 1].num = 1
      areg = 33
    }
  },
  //清空
  Dclear4: function () {
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x - 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 2][this.x].num = 0
  },
  //变色
  DchangeColor4: function () {
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 2][this.x].num = 2
    get()
  },
  //第五种类型
  Echange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 1][this.x + 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
    } else {
      arr[this.y - 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 42
    }
  },
  Eclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 1][this.x + 1].num = 0
  },
  EchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 1][this.x + 1].num = 2
    get()
  },
  Echange2: function () {
    if (arr[this.y - 1][this.x].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y - 1][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x + 1].num = 1
      areg = 41
    }
  },
  Eclear2: function () {
    arr[this.y - 1][this.x].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  EchangeColor2: function () {
    arr[this.y - 1][this.x].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  Gchange1: function () {
    if (arr[this.y][this.x].num != 2 &&
      arr[this.y][this.x + 1].num != 2 &&
      arr[this.y + 1][this.x].num != 2 &&
      arr[this.y + 1][this.x - 1].num != 2) {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
    } else {
      arr[this.y - 1][this.x - 1].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
      areg = 62
    }
  },
  Gclear1: function () {
    arr[this.y][this.x].num = 0
    arr[this.y][this.x + 1].num = 0
    arr[this.y + 1][this.x].num = 0
    arr[this.y + 1][this.x - 1].num = 0
  },
  GchangeColor1: function () {
    arr[this.y][this.x].num = 2
    arr[this.y][this.x + 1].num = 2
    arr[this.y + 1][this.x].num = 2
    arr[this.y + 1][this.x - 1].num = 2
    get()
  },
  Gchange2: function () {
    if (arr[this.y - 1][this.x - 1].num != 2 &&
      arr[this.y][this.x - 1].num != 2 &&
      arr[this.y][this.x].num != 2 &&
      arr[this.y + 1][this.x].num != 2) {
      arr[this.y - 1][this.x - 1].num = 1
      arr[this.y][this.x - 1].num = 1
      arr[this.y][this.x].num = 1
      arr[this.y + 1][this.x].num = 1
    } else {
      arr[this.y][this.x].num = 1
      arr[this.y][this.x + 1].num = 1
      arr[this.y + 1][this.x].num = 1
      arr[this.y + 1][this.x - 1].num = 1
      areg = 61
    }
  },
  Gclear2: function () {
    arr[this.y - 1][this.x - 1].num = 0
    arr[this.y][this.x - 1].num = 0
    arr[this.y][this.x].num = 0
    arr[this.y + 1][this.x].num = 0
  },
  GchangeColor2: function () {
    arr[this.y - 1][this.x - 1].num = 2
    arr[this.y][this.x - 1].num = 2
    arr[this.y][this.x].num = 2
    arr[this.y + 1][this.x].num = 2
    get()
  }
}

//设置原点坐标
let a = new Obj(5, 0)
//渲染图形
let areg = 1
a.Achange1()
render()

//随机图形函数
let num1 = 0
function nums() {
  num1 = Math.floor(Math.random() * 100)
  if (num1 <= 15) {
    areg = 1
    a.Achange1()
  }
  if (num1 > 15 && num1 <= 25) {
    areg = 12
    a.Bchange2()
  }
  if (num1 > 25 && num1 <= 40) {
    areg = 21
    a.Cchange1()
  }
  if (num1 > 40 && num1 <= 55) {
    areg = 31
    a.Dchange1()
  }
  if (num1 > 55 && num1 <= 70) {
    areg = 41
    a.Echange1()
  }
  if (num1 > 70 && num1 <= 85) {
    areg = 51
    a.Fchange1()
  }
  if (num1 > 85 && num1 <= 100) {
    areg = 61
    a.Gchange1()
  }
}

//得分函数
function get() {
  let getArr = []
  arr.forEach((item, index) => {
    //筛选颜色为灰色的格子
    const arr0 = item.filter(function (item02) {
      return item02.num == 2
    })
    //console.log(arr0);
    //数组长度为9时，说明这一排都是灰色，就清除
    if (arr0.length === 9) {
      //同时将数据放入getArr中，起到一个计数效果
      getArr.push(arr0)
      for (let i = 0; i < arr0.length; i++) {
        arr0[i].num = 0
      }
      //从下往上遍历,目的是把所有Num为2的格子往下移动一格,遍历选中Num为2的格子，将其清空，然后把其下一排对应的格子赋值
      for (let i = index - 1; i > 0; i--) {
        arr[i].forEach((item, index1) => {
          if (item.num === 2) {
            item.num = 0
            arr[i + 1][index1].num = 2
          }
        })
      }
      render()
    }
  })
  //得分判断
  if (getArr.length == 1) {
    Defen += 1
  } else if (getArr.length == 2) {
    Defen += 4
  } else if (getArr.length == 3) {
    Defen += 10
  } else if (getArr.length == 4) {
    Defen += 20
  }
  defen.innerHTML = `得分${Defen}`
}

//游戏结束判定
function end() {
  arr[0].forEach(item => {
    if (item.num === 2) {
      if (Defen > Fenshu) {
        //存分数
        localStorage.setItem('fenshu1', Defen)
      }
      setTimeout(function () {
        alert('游戏结束!')
        location.href = "./俄罗斯方块2.5.html"
      }, 100)
    }
  })
}

let flag = true
let timer = null
//暂停功能
document.addEventListener('keydown', function (e) {
  if (flag) {
    if (e.key === 'Enter') {
      console.log(11);
      clearInterval(timer)
      flag = !flag
      console.log(flag);
    }
  } else {
    if (e.key === 'Enter') {
      if (Defen <= 20) {
        timer = setInterval(function () {
          down()
        }, 500)
      } else {
        timer = setInterval(function () {
          down()
        }, 300)
      }
      console.log(11);
      flag = true
    }
  }
})

//键盘事件
function down() {
  adown()
  if (areg === 1) {
    a.Achange1()
    render()
  } else if (areg === 2) {
    a.Achange2()
    render()
  } else if (areg === 3) {
    a.Achange3()
    render()
  } else if (areg === 4) {
    a.Achange4()
    render()
  } else if (areg === 51) {
    a.Fchange1()
    render()
  } else if (areg === 52) {
    a.Fchange2()
    render()
  } else if (areg === 53) {
    a.Fchange3()
    render()
  } else if (areg === 54) {
    a.Fchange4()
    render()
  } else if (areg === 11) {
    a.Bchange1()
    render()
  } else if (areg === 12) {
    a.Bchange2()
    render()
  } else if (areg === 21) {
    a.Cchange1()
    render()
  } else if (areg === 31) {
    a.Dchange1()
    render()
  } else if (areg === 32) {
    a.Dchange2()
    render()
  } else if (areg === 33) {
    a.Dchange3()
    render()
  } else if (areg === 34) {
    a.Dchange4()
    render()
  } else if (areg === 41) {
    a.Echange1()
    render()
  } else if (areg === 42) {
    a.Echange2()
    render()
  } else if (areg === 61) {
    a.Gchange1()
    render()
  } else if (areg === 62) {
    a.Gchange2()
    render()
  }
  xiaBianjie()
}
document.addEventListener('keydown', function (e) {
  if (flag) {
    if (e.key === 'ArrowDown') {
      down()
    }
    if (e.key === 'ArrowRight') {
      aright()
    }
    if (e.key === 'ArrowLeft') {
      aleft()
    }
    if (e.key === 'ArrowUp') {
      achange()
    }
  }
}

)

//定时器
timer && clearInterval(timer)
if (Defen <= 20) {
  timer = setInterval(function () {
    down()
  }, 500)
} else {
  timer = setInterval(function () {
    down()
  }, 300)
}

//渲染函数
function render() {
  document.querySelector('table').innerHTML = ''
  arr.forEach(item => {
    let tr = document.createElement('tr')
    //console.log(item);
    item.forEach(function (item2) {
      let td = document.createElement('td')
      tr.appendChild(td)
      if (item2.num === 1) {
        td.classList.add('bgc1')
      }
      else if (item2.num === 2) {
        td.classList.remove('bgc1')
        td.classList.add('bgc2')
      }
    })
    document.querySelector('table').appendChild(tr)
  })
}

//下降函数
function adown() {
  if (areg === 1) {
    if (arr[a.y + 1][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
      a.Aclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.AchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 2) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Aclear2()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.AchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 3) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Aclear3()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.AchangeColor3()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 4) {
    if (arr[a.y + 3][a.x - 1].num != 2 && arr[a.y + 1][a.x].num != 2) {
      a.Aclear4()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.AchangeColor4()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 51) {
    if (arr[a.y + 1][a.x].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 1][a.x + 1].num != 2) {
      a.Fclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.FchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 52) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Fclear2()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.FchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 53) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Fclear3()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.FchangeColor3()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 54) {
    if (arr[a.y + 3][a.x].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
      a.Fclear4()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.FchangeColor4()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 11) {
    //console.log(a.y);
    if (arr[a.y + 4][a.x].num != 2) {
      a.Bclear1()
      a.x = a.x
      a.y = a.y + 1
    } else {
      a.BchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 12) {
    //console.log(a.y);
    if (arr[a.y + 1][a.x].num != 2 && arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 1][a.x + 1].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
      a.Bclear2()
      a.x = a.x
      a.y = a.y + 1
    } else {
      a.BchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 21) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Cclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.CchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 31) {
    if (arr[a.y + 2][a.x + 1].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 2][a.x].num != 2) {
      a.Dclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.DchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 32) {
    if (arr[a.y + 3][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
      a.Dclear2()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.DchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 33) {
    if (arr[a.y + 1][a.x + 1].num != 2 && arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 2][a.x].num != 2) {
      a.Dclear3()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.DchangeColor3()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 34) {
    if (arr[a.y + 3][a.x].num != 2 && arr[a.y + 2][a.x - 1].num != 2) {
      a.Dclear4()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.DchangeColor4()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 41) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x + 1].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
      a.Eclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.EchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 42) {
    if (arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 1][a.x].num != 2) {
      a.Eclear2()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.EchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 61) {
    if (arr[a.y + 2][a.x].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 1][a.x + 1].num != 2) {
      a.Gclear1()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.GchangeColor1()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  if (areg === 62) {
    if (arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 2][a.x].num != 2) {
      a.Gclear2()
      a.x = a.x
      a.y = a.y + 1
      //console.log(a);
    } else {
      a.GchangeColor2()
      a = new Obj(5, 0)
      nums()
      render()
      end()
    }
  }
  //console.log(arr[5][10].num);
}
//下边界函数
function xiaBianjie() {
  if (areg === 1 || areg === 2 || areg === 3 || areg === 51 || areg === 52 || areg === 53 || areg === 21 || areg === 31 || areg === 33 || areg === 41 || areg === 42 || areg === 61 || areg === 62) {
    if (a.y === 10) {
      areg === 1 && a.AchangeColor1()
      areg === 2 && a.AchangeColor2()
      areg === 3 && a.AchangeColor3()
      areg === 51 && a.FchangeColor1()
      areg === 52 && a.FchangeColor2()
      areg === 53 && a.FchangeColor3()
      areg === 21 && a.CchangeColor1()
      areg === 31 && a.DchangeColor1()
      areg === 33 && a.DchangeColor3()
      areg === 41 && a.EchangeColor1()
      areg === 42 && a.EchangeColor2()
      areg === 61 && a.GchangeColor1()
      areg === 62 && a.GchangeColor2()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 9) {
      a.y = 9
    }
  } else if (areg === 11) {
    if (a.y === 8) {
      areg === 11 && a.BchangeColor1()
      // areg === 12 && a.AchangeColor2()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 7) {
      a.y = 7
    }
  } else if (areg === 12) {
    if (a.y === 11) {
      areg === 12 && a.BchangeColor2()
      // areg === 12 && a.AchangeColor2()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 10) {
      a.y = 10
    }
  } else if (areg === 32) {
    if (a.y === 9) {
      areg === 32 && a.DchangeColor2()
      // areg === 12 && a.AchangeColor2()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 8) {
      a.y = 8
    }
  } else if (areg === 34) {
    if (a.y === 9) {
      areg === 34 && a.DchangeColor4()
      // areg === 12 && a.AchangeColor2()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 8) {
      a.y = 8
    }
  } else if (areg === 4 || areg === 54) {
    if (a.y === 9) {
      areg === 4 && a.AchangeColor4()
      areg === 54 && a.FchangeColor4()
      a = new Obj(5, 0)
      nums()
      setTimeout(function () {
        render()
      }, 20)
    }
    if (a.y >= 8) {
      a.y = 8
    }
  }
}
//右移动
function aright() {
  if (a.x <= 6) {
    if (areg === 1) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
        //console.log(a.x);
        a.Aclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Achange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 2) {
      if (arr[a.y + 1][a.x + 2].num != 2 && arr[a.y][a.x + 2].num != 2 && arr[a.y - 1][a.x + 2].num != 2) {
        a.Aclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Achange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 3) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x].num != 2) {
        //console.log(a.x);
        a.Aclear3()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Achange3()
      } else {
        a.x = a.x
      }
    }
    else if (areg === 51) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x].num != 2) {
        //console.log(a.x);
        a.Fclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Fchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 52) {
      if (arr[a.y + 1][a.x + 2].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y - 1][a.x + 1].num != 2) {
        a.Fclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Fchange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 53) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
        //console.log(a.x);
        a.Fclear3()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Fchange3()
      } else {
        a.x = a.x
      }
    }
    else if (areg === 21) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
        //console.log(a.x);
        a.Cclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Cchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 31) {
      if (arr[a.y][a.x + 1].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
        //console.log(a.x);
        a.Dclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Dchange1()
      } else {
        a.x = a.x
      }
    }
    else if (areg === 32) {
      if (arr[a.y + 1][a.x + 2].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
        a.Dclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Dchange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 33) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x + 1].num != 2) {
        //console.log(a.x);
        a.Dclear3()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Dchange3()
      } else {
        a.x = a.x
      }
    } else if (areg === 41) {
      if (arr[a.y][a.x + 1].num != 2 && arr[a.y + 1][a.x + 2].num != 2) {
        //console.log(a.x);
        a.Eclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Echange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 61) {
      if (arr[a.y][a.x + 2].num != 2 && arr[a.y + 1][a.x + 1].num != 2) {
        //console.log(a.x);
        a.Gclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Gchange1()
      } else {
        a.x = a.x
      }
    }
  }
  if (a.x < 6) {
    if (areg === 12) {
      if (arr[a.y][a.x + 3].num != 2) {
        a.Bclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Bchange2()
      } else {
        a.x = a.x
      }
    }
  }
  if (a.x < 8) {
    if (areg === 11) {
      console.log(a.x);
      if (arr[a.y][a.x + 1].num != 2 && arr[a.y + 1][a.x + 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2 && arr[a.y + 3][a.x + 1].num != 2) {
        a.Bclear1()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Bchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 4) {
      if (arr[a.y + 1][a.x].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y + 2][a.x].num != 2) {
        a.Aclear4()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Achange4()
      } else {
        a.x = a.x
      }
    } else if (areg === 54) {
      if (arr[a.y + 1][a.x + 1].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
        a.Fclear4()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Fchange4()
      } else {
        a.x = a.x
      }
    } else if (areg === 34) {
      if (arr[a.y + 1][a.x + 1].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y + 2][a.x + 1].num != 2) {
        a.Dclear4()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Dchange4()
      } else {
        a.x = a.x
      }
    } else if (areg === 42) {
      if (arr[a.y + 1][a.x].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y - 1][a.x + 1].num != 2) {
        a.Eclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Echange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 62) {
      if (arr[a.y + 1][a.x + 1].num != 2 && arr[a.y][a.x + 1].num != 2 && arr[a.y - 1][a.x].num != 2) {
        a.Gclear2()
        a.x = a.x + 1
        a.y = a.y
        //console.log(a);
        a.Gchange2()
      } else {
        a.x = a.x
      }
    }
  }
  render()
}
//左移动
function aleft() {
  if (a.x > 1) {
    if (areg === 1) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x].num != 2) {
        a.Aclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Achange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 3) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 2].num != 2) {
        a.Aclear3()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Achange3()
      } else {
        a.x = a.x
      }
    } else if (areg === 4) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 2].num != 2 && arr[a.y + 2][a.x - 2].num != 2) {
        a.Aclear4()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Achange4()
      } else {
        a.x = a.x
      }
    }
    else if (areg === 51) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 2].num != 2) {
        a.Fclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Fchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 53) {
      if (arr[a.y][a.x].num != 2 && arr[a.y + 1][a.x - 2].num != 2) {
        a.Fclear3()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Fchange3()
      } else {
        a.x = a.x
      }
    } else if (areg === 54) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 2][a.x - 1].num != 2) {
        a.Fclear4()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Fchange4()
      } else {
        a.x = a.x
      }
    }
    else if (areg === 12) {
      if (arr[a.y][a.x - 2].num != 2) {
        a.Bclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Bchange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 31) {
      if (arr[a.y + 1][a.x - 2].num != 2 && arr[a.y][a.x - 1].num != 2) {
        a.Dclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Dchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 33) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
        a.Dclear3()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Dchange3()
      } else {
        a.x = a.x
      }
    } else if (areg === 34) {
      if (arr[a.y + 1][a.x - 2].num != 2 && arr[a.y][a.x - 1].num != 2 && arr[a.y + 2][a.x - 1].num != 2) {
        a.Dclear4()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Dchange4()
      } else {
        a.x = a.x
      }
    } else if (areg === 41) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
        a.Eclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Echange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 42) {
      if (arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 2].num != 2 && arr[a.y - 1][a.x - 1].num != 2) {
        a.Eclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Echange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 61) {
      if (arr[a.y + 1][a.x - 2].num != 2 && arr[a.y][a.x - 2].num != 2) {
        a.Gclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Gchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 62) {
      if (arr[a.y - 1][a.x - 2].num != 2 && arr[a.y][a.x - 2].num != 2 && arr[a.y + 1][a.x - 1].num != 2) {
        a.Gclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Gchange2()
      } else {
        a.x = a.x
      }
    }

  } if (a.x > 0) {
    if (areg === 2) {
      if (arr[a.y + 1][a.x - 1].num != 2 && arr[a.y][a.x].num != 2 && arr[a.y - 1][a.x].num != 2) {
        a.Aclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Achange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 52) {
      if (arr[a.y + 1][a.x - 1].num != 2 && arr[a.y][a.x - 1].num != 2 && arr[a.y - 1][a.x - 1].num != 2) {
        a.Fclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Fchange2()
      } else {
        a.x = a.x
      }
    } else if (areg === 11) {
      if (arr[a.y][a.x - 1].num != 2 && arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 2][a.x - 1].num != 2 && arr[a.y + 3][a.x - 1].num != 2) {
        a.Bclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Bchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 21) {
      if (arr[a.y + 1][a.x - 1].num != 2 && arr[a.y][a.x - 1].num != 2) {
        a.Cclear1()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Cchange1()
      } else {
        a.x = a.x
      }
    } else if (areg === 32) {
      if (arr[a.y][a.x - 1].num != 2 && arr[a.y + 1][a.x - 1].num != 2 && arr[a.y + 2][a.x - 1].num != 2) {
        a.Dclear2()
        a.x = a.x - 1
        a.y = a.y
        //console.log(a);
        a.Dchange2()
      } else {
        a.x = a.x
      }
    }

  }
  render()

}
//变形状
function achange() {
  if (areg === 1) {
    if (a.y == 0) {
      areg = 1
    } else {
      areg = 2
      a.Aclear1()
      a.Achange2()
    }
    render()
  } else if (areg === 2) {
    if (a.x < 1) {
      areg = 2
    } else {
      areg = 3
      a.Aclear2()
      a.Achange3()
    }
    render()
  } else if (areg === 3) {
    areg = 4
    a.Aclear3()
    a.Achange4()
    render()
  } else if (areg === 4) {
    if (a.x > 7) {
      areg = 4
    } else {
      areg = 1
      a.Aclear4()
      a.Achange1()
    }
    render()
  } else if (areg === 51) {
    if (a.y == 0) {
      areg = 51
    } else {
      areg = 52
      a.Fclear1()
      a.Fchange2()
    }
    render()
  } else if (areg === 52) {
    if (a.x < 1) {
      areg = 52
    } else {
      areg = 53
      a.Fclear2()
      a.Fchange3()
    }
    render()
  } else if (areg === 53) {
    areg = 54
    a.Fclear3()
    a.Fchange4()
    render()
  } else if (areg === 54) {
    if (a.x > 7) {
      areg = 54
    } else {
      areg = 51
      a.Fclear4()
      a.Fchange1()
    }
    render()
  } else if (areg === 11) {
    if (a.x > 0 && a.x < 7) {
      areg = 12
      a.Bclear1()
      a.Bchange2()
    } else {
      areg = 11
    }
    render()
  } else if (areg === 12) {
    areg = 11
    a.Bclear2()
    a.Bchange1()

    render()
  } else if (areg === 31) {
    areg = 32
    a.Dclear1()
    a.Dchange2()
    render()
  } else if (areg === 32) {
    if (a.x < 1) {
      areg = 32
    } else {
      areg = 33
      a.Dclear2()
      a.Dchange3()
    }
    render()
  } else if (areg === 33) {
    areg = 34
    a.Dclear3()
    a.Dchange4()
    render()
  } else if (areg === 34) {
    if (a.x > 7) {
      areg = 34
    } else {
      areg = 31
      a.Dclear4()
      a.Dchange1()
    }
    render()
  }
  else if (areg === 41) {
    if (a.y == 0) {
      areg = 41
    } else {
      areg = 42
      a.Eclear1()
      a.Echange2()
    }
    render()
  } else if (areg === 42) {
    if (a.x < 1 || a.x > 7) {
      areg = 42
    } else {
      areg = 41
      a.Eclear2()
      a.Echange1()
    }
    render()
  }
  else if (areg === 61) {
    if (a.y == 0) {
      areg = 61
    } else {
      areg = 62
      a.Gclear1()
      a.Gchange2()
    }
    render()
  } else if (areg === 62) {
    if (a.x < 1 || a.x > 7) {
      areg = 62
    } else {
      areg = 61
      a.Gclear2()
      a.Gchange1()
    }
    render()
  }
}